<html>
<head><meta charset="utf-8"><title>tuple in rust · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/tuple.20in.20rust.html">tuple in rust</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="235488949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/tuple%20in%20rust/near/235488949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> xiaochen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/tuple.20in.20rust.html#235488949">(Apr 21 2021 at 10:50)</a>:</h4>
<p>When I read the tuple part of the official document, I found that the compiler does not support (x, y, z), so I need to change it to (_ x,_ y,_ z) Why? Has the official document not been updated?</p>



<a name="235489128"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/tuple%20in%20rust/near/235489128" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> xiaochen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/tuple.20in.20rust.html#235489128">(Apr 21 2021 at 10:52)</a>:</h4>
<p>I'm a beginner,thanks! <span aria-label="grinning" class="emoji emoji-1f600" role="img" title="grinning">:grinning:</span></p>



<a name="235489855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/tuple%20in%20rust/near/235489855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pachi <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/tuple.20in.20rust.html#235489855">(Apr 21 2021 at 10:59)</a>:</h4>
<p>That's a bit strange.  You can define tuples using that syntax (with types) and use them (with values) and the leading underscores would only be useful to unpack unused tuple values and avoid getting warning lints.</p>



<a name="235490273"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/tuple%20in%20rust/near/235490273" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pachi <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/tuple.20in.20rust.html#235490273">(Apr 21 2021 at 11:02)</a>:</h4>
<p>Anyhow, <span class="user-mention" data-user-id="407239">@xiaochen</span> ,  with only that fragment (which is not runnable code) it's quite difficult to see what's your problem. Anyway, for this kind of help you may find the rust community discord server a better venue <a href="https://discord.gg/jmgJDgBE">https://discord.gg/jmgJDgBE</a><br>
These zulip channels are mostly for the development of the language/compiler/tools themselves.</p>



<a name="235494006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/tuple%20in%20rust/near/235494006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> xiaochen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/tuple.20in.20rust.html#235494006">(Apr 21 2021 at 11:34)</a>:</h4>
<p>fn main() {<br>
    let tup = (500, 6.4, 1);</p>
<div class="codehilite"><pre><span></span><code>let (_x, _y, _z) = tup;

println!(&quot;The value of y is: {}&quot;, _y);
</code></pre></div>

<p>}</p>
<p>If I use 'x' not '_x'<br>
there will be:<br>
warning: unused variable: <code>x</code><br>
 --&gt; main.rs:4:10<br>
  |<br>
4 |     let (x, y, z) = tup;<br>
  |          ^ help: if this is intentional, prefix it with an underscore: <code>_x</code></p>



<a name="235495186"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/tuple%20in%20rust/near/235495186" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pachi <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/tuple.20in.20rust.html#235495186">(Apr 21 2021 at 11:44)</a>:</h4>
<p>So, you could only add an underscore to the unused variables, in your case, _x and _z and still keep naming y as such, and not _y. Though, that is a warning, not a compilation error.</p>



<a name="235499620"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/tuple%20in%20rust/near/235499620" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/tuple.20in.20rust.html#235499620">(Apr 21 2021 at 12:20)</a>:</h4>
<p>you can also use <code>let (_, y, _) = tup;</code> if you actually don't care about the other values (and don't care to label them for the reader either)</p>



<a name="235534551"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/tuple%20in%20rust/near/235534551" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> xiaochen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/tuple.20in.20rust.html#235534551">(Apr 21 2021 at 15:47)</a>:</h4>
<p>Oh，I see，thank you!!!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>